[Home]Sample HAL And ClassicLadder

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

Search:

Contents

This page is WAY out of date now .
The concepts are the same but the version of classicladder is different and HAL has matured.
Go ahead and look at this page, then go here-> ClassicLadder

1. Introduction
2. Testing EMC2 with ClassicLadder
3. The default ladder
4. Editing Ladder
5. HAL Configuration for demo_step_cl

1. Introduction

There is a sample configuration in emc2 that allows you to see how EMC2, HAL, and ClassicLadder can be made to work together. This was intended to be a very quick, newbee's look at "2" but it has turned out to be quite a chase. The goal of this page is to expand the reach of the new systems for testing and feature requests. You will want to set up a system for compiling so you can keep up with the rapidly changing code. It's not all that difficult. Done once, it is easily repeatable. You can be pretty certain that it will compile because EMC2's code is tested daily.

The instructions below assume that you've already compiled emc2 on your system; Instructions on compiling the latest testing release can be found at Testing. The instructions also assume that you know something about LadderProgramming.

This page is quite dated but the ideas are basically the same (Feb 08)

2. Testing EMC2 with ClassicLadder

Now you can test this same system using ClassicLadder as modified for emc. The command for this is

 scripts/emc  configs/demo_step_cl/demo_step_cl.ini

The demo_step_cl files start up the EMC, HAL, and ClassicLadder. They also start up the display part of ladder so that you can edit the machine logic to suit your machine. These displays include the ladder editor, signal display, and ladder. This starts an overwhelming pile of widgets on the screen. I've hidden a couple of the screens and moved others around so that you can see the essential stuff in the picture below

upload:display_all.png

3. The default ladder

This section begins to detail the operation of ladder. Connections are only briefly defined here. The way that these are setup are listed in detail in the HAL section. The list of input and output signals are:

If you are anything like me, these names will help some but you will be confused about how they work as you study the sample ladder images. Hang in there and the details should come clear after some study.

The Estop Ladder Rung The image on the right shows the first rung of the ladder program we are using in demo_step_cl. Notice that the wire at the left side of each row is missing. Each row represents a different type of estop operation. Only one of the rows should be wired in at a time. You'll learn how to edit the ladder later. The pictures below show how each row works when it is connected. upload:estop_group.png

Estop Type 1 This ESTOP is like you might use for a Sherline or other minimill that uses no external estop button. This uses only the estop-on or estop-off commands from a graphical interface. Notice that the first row has been activated by connecting it to the left power line and that the user-enable-out (I0) contact has been closed. When the ladder shows red lines or devices it means that those lines and devices are active. upload:estop_group1.png

Estop Type 2 This uses only an external estop button. Notice that we've used a normally closed contact (NC). The red indicates that this contact is closed and that estop-enable-in (Q0) is energized. When the external button contact is held open the EMC remains in the estop condition. As soon as the external contact is closed the EMC will switch into the emc-reset state. You'll want to use a maintained sort of pushbutton for this. upload:estop_group2.png

Estop Type 3 This system allows either the estop button on the graphical interface or an external maintained pushbutton can initiate an estop condition within the EMC. Both the GUI and the external button will need to be set to enable in order for the system to return to enabled. You can see that the external estop is preventing the system from being enabled. upload:estop_group5.png

Estop Type 4 This is just about the ultimate in PC based estop circuits. Either a gui button or an external button will cause an estop condition in the EMC. This condition is maintained until both the external button is enabled and the GUI signals a user-enable-out. Here you can see that a normally open contact from Q0 latches itself in the enabled condition. This latching requires the additional user-request-enable momentary signal to pull the enable coil so that the latching happens. This signal is all that is needed to move the EMC into the enabled condition. It would easily be possible to add an external press-to-estop momentary button with a pull-to-reset contact to this setup. upload:estop_group9.png

Look at the ladder on the right and decide what the operator must do to enable the EMC? Answer backwards is teser-potse ro <1F> sserp dna nottub lanretxe eht esaeler. upload:estop_group8.png

A quick look at the intermittent lube system setup in the second rung of demo_step_cl.clp.

upload:lube1.png

T0 and T1 are set up to toggle. As soon as the EMC sees machine on it asks for lube so the I3 contact closes sending a signal through B0 to T0. As soon as T0 gets power it begins to count down and it turns on the R signal out. That output turns on Q1 which is connected to a parport pin that turns on the lube pump. The details of these hardware connections are described in the HAL section below.

You'll notice that the R and D outputs from T0 are connected to set and reset Q1. This way we are able to avoid any interaction between rungs. If we used an ordinary ladder coil, it might switch on and off several times before it settled down and started working properly. This coil is the ladder equivalent of a debounce thing or a latching coil.

When T0 reaches the end of it's count, it turns off Q1. This stops the lube pump and closes the NC contact on the next row. This causes T1 to begin counting and pulls its R output low. This energizes the internal ClassicLadder coil B0 and opens the NC contact to T0. This resets T0 to it's count so that when T1 times out, the lube pump will come on again. Once you get the hang of reading ladder it is easier to see the logic there than to read it here.

There is one other thing that happens when EMC turns the machine on. Power is supplied through the normally open, but now closed, I4 and begins a countdown on T2. If I4 does not open in 9.9 minutes, Q2 will turn off and that will notify the EMC that there is a problem with lubrication on the machine. I designed my lube system with a little pressure switch on the output of the pump. Once the lube pump has run for a few seconds, this sensor opens and resets T2. This keeps happening until the lube pump runs out of oil or it's motor dies. Once that happens and T2 times out, the error message is returned to EMC.

4. Editing Ladder

The ladder display widgets leave something to be desired and we will need to clean them up and make editing a lot more servicable but for now it is way ahead of where we were with the EMC.

upload:editor1.png When you started emc2 using the command "scripts/emc configs/demo_step_cl/demo_step_cl.ini" all of the widgets needed to edit ladder are available to you. Move the ladder display to the run you want to edit. This can be a bit tricky. There are little gray lines across the display between rungs.

Let's start by editing the type of estop we want to use for the system. Get to the top run of the ladder display. It should look something like the second row of the estop image above. Press the modify button on the editor and select the horizontal line. Selecting these is not real easy, click near the top of the icon and make certain that a box appears around the one that you really want to use. The horizontal line can be used to turn on a line or off a line. To turn off the line on the top row left, click it and then move down to the second row and click there. You should now have the second row connected and ready to run. Press the okay button and you should see EMC estopped.

In order to use this line you'll need to connect a switch of some sort from parport ground to pin 10. Once you've got that switch in place, you can test all of the different setups.

If you make enough of a mess of ladder that you need to start over, simply close down the emc using either the menu quit or the x on the tkemc display. This closes out ladder but does not save your changes. To save changes you'll need to select save as and find the file demo_step_cl.clp on the right side of that widget, click on it and press save. I'd make a backup of that file before I started editing in case of major screwups. In fact you can use the displays that you saw when you ran the command scripts/emc to make a copy of the entire demo_step_cl system and name it whatever you like. That way you can work with all of the files and see how they fit together to make the system.

In our next edit let's work on changing the timing of the lube rung. To do this you'll need to move that rung into the ladder display and press modify on the edit widget.

upload:set_time.png

Notice that the long arrow near the bottom of the edit widgets has a box around it. That is the thing we need to use to edit parameter values for any ladder element. With that active, you simply point at the element you want to examine or change and you'll see it's parameters show up in the little parameter display window. Here you can see the number of the timer we are looking at in the top row. It is timer 0. The second row shows the time interval to be used. This can be minutes, seconds, or tenths of seconds. The bottom row allows you to set the actual number of time intervals that will be counted.

5. HAL Configuration for demo_step_cl

Now it is time to begin to discover how HAL and Ladder interact to do the things they do. Early in this section we will be depending upon halcmd. Halcmd is a utility that lets us setup and look at connections. In the HAL. The first two or three images below are made using the linux watch command. Watch keeps repeating a command given to it every so often. By combining watch and halcmd we can see what is going on inside the HAL.

upload:watch-cl.png

Here we can see the connections and the state of each classicladder signal. This is quite a bit like watching the running ladder. See if you can figure out what condition the lube stuff is in, and what else is running.

upload:watch-iocontrol.png

Here we have a listing of another HAL module. This one is named iocontrol. It can read and write the NML messages that EMC uses to tell IO to turn on or off and what condition (status) all of the IO currently is in. You may be able to pick out several signals that we aren't using or at least you have not seen yet in ladder.

It will probably be easier to read the return from this halcmd if I put the plain text here.

Every 2s: bin/halcmd show pin iocontrol Sun Nov 20 12:10:41 2005

Component Pins: Owner Type Dir Value Name

 03    bit   -W     TRUE       iocontrol.0.coolant-flood ==> iocontrol.0.coolant-flood
 03    bit   -W     TRUE       iocontrol.0.coolant-mist ==> iocontrol.0.coolant-mist
 03    bit   R-     TRUE       iocontrol.0.emc-enable-in <== iocontrol.0.emc-enable-in
 03    bit   -W     TRUE       iocontrol.0.lube ==> iocontrol.0.lube
 03    bit   R-     TRUE       iocontrol.0.lube_level <== iocontrol.0.lube_level
 03    bit   -W     FALSE      iocontrol.0.spindle-brake
 03    bit   -W     FALSE      iocontrol.0.spindle-decr-speed
 03    bit   -W     TRUE       iocontrol.0.spindle-forward ==> iocontrol.0.spindle-forward
 03    bit   -W     FALSE      iocontrol.0.spindle-incr-speed
 03    bit   -W     TRUE       iocontrol.0.spindle-on
 03    bit   -W     FALSE      iocontrol.0.spindle-reverse ==> iocontrol.0.spindle-reverse
 03    float R-   0.00000e+00  iocontrol.0.spindle-speed-in
 03    float -W   5.00000e+02  iocontrol.0.spindle-speed-out
 03    bit   -W     FALSE      iocontrol.0.tool-change ==> iocontrol.0.tool-change
 03    bit   R-     FALSE      iocontrol.0.tool-changed <== iocontrol.0.tool-change
 03    u8    -W      0  (00)   iocontrol.0.tool-prep-number
 03    bit   -W     FALSE      iocontrol.0.tool-prepare ==> iocontrol.0.tool-prepare
 03    bit   R-     FALSE      iocontrol.0.tool-prepared <== iocontrol.0.tool-prepare
 03    bit   -W     TRUE       iocontrol.0.user-enable-out ==> iocontrol.0.user-enable-out
 03    bit   -W     FALSE      iocontrol.0.user-request-enable ==> iocontrol.0.user-request-enable

(more later)


LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited September 28, 2008 1:02 am by Chester (diff)Published under a Creative Commons License